package uiLayer;
import modelLayer.*;
import controlLayer.*;
import java.util.Scanner;

/**
 * Write a description of class MainMenuUI here.
 * 
 * @author (Gruupe E) 
 * @version (06-11-2014)
 */
public class MainMenuUI
{
    private PersonUI personUI;
    private DvdMainUI dvdUI;
    private LoanUI loanUI;
    private PersonController personController;
    private DVDController dvdController;
    private LoanController loanController;

    /**
     * Constuctor for MainMenuUI 
     *
     */
    public MainMenuUI()
    {
        personController = new PersonController();
        dvdController = new DVDController();
        loanController = new LoanController();
        personUI = new PersonUI(personController);
        dvdUI = new DvdMainUI(dvdController);
        loanUI = new LoanUI(loanController);
    }

    /**
     * An example of a method - replace this comment with your own
     * 
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y 
     */
    public void start()
    {
        mainMenu();
    }

    /**
     * Runs a while-loop, prompting the user for input and calls the sub-menus.
     */
    private void mainMenu()
    {
        boolean exit = false;

        while(!exit)
        {
            String choice = writeMainMenu();
            if(choice.equals("1"))
            {
                friendsMenu();
            }

            else if(choice.equals("2"))
            {
                dvdsMenu();
            }

            else if(choice.equals("3"))
            {
                loanMenu();
            }

            else if(choice.equals("4"))
            {
                exit = true;
            }
            else
            {
                System.out.println("\nInvalid types. Please try again.");
            }
        }
    }

    /**
     * A private method that displays a set of options and promts the user to enter an int.
     * @return  int
     */
    private String writeMainMenu()
    {
        Scanner keyboard = new Scanner(System.in);
        blankLines();
        System.out.println("*** MainMenu ***");
        System.out.println("1. Friends");
        System.out.println("2. DVDs");
        System.out.println("3. Loan");
        System.out.println("4. Close");

        System.out.println("\nPlease choose a number");

        String choice = keyboard.nextLine();
        return choice;
    }

    /**
     * calls the start() method on the personUI.
     */
    private void friendsMenu()
    {
        personUI.start();
    }

    /**
     * calls the start() method on the dvdsUI.
     */
    private void dvdsMenu()
    {
        dvdUI.start();
    }

    /**
     * calls the start() method on the loanUI.
     */
    private void loanMenu()
    {
        loanUI.start();
    }

    /**
     * This method adds 5 blank lines.
     */
    private void blankLines()
    {
        for(int i = 0; i < 5; i++)
        {
            System.out.println();
        }
    }
}
